using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Buff工厂类 - 统一管理Buff的创建
/// </summary>
public static class BuffFactory
{
    /// <summary>
    /// 根据BuffType创建对应的Buff实例
    /// </summary>
    /// <param name="buffType">Buff类型</param>
    /// <param name="buffData">Buff数据</param>
    /// <param name="caster">施法者</param>
    /// <param name="target">目标</param>
    /// <returns>创建的Buff实例</returns>
    public static BuffBase CreateBuff(BuffType buffType, BuffData buffData, Entity caster, Entity target)
    {
        if (buffData == null || caster == null || target == null)
        {
            Logger.LogError("BuffFactory", "参数不能为空");
            return null;
        }

        switch (buffType)
        {
            // 状态类Buff
            case BuffType.Burn:
                return new BurnBuff(buffData, caster, target);
            case BuffType.Poison:
                return new PoisonBuff(buffData, caster, target);
            case BuffType.Bleed:
                return new BleedBuff(buffData, caster, target);
            case BuffType.Shock:
                return new ShockBuff(buffData, caster, target);
            case BuffType.Chill:
                return new ChillBuff(buffData, caster, target);
            case BuffType.Curse:
                return new CurseBuff(buffData, caster, target);
            case BuffType.Corrosion:
                return new CorrosionBuff(buffData, caster, target);
            case BuffType.Regeneration:
                return new RegenerationBuff(buffData, caster, target);
            case BuffType.LifeLeech:
                return new LifeLeechBuff(buffData, caster, target);
            case BuffType.ManaRegen:
                return new ManaRegenBuff(buffData, caster, target);

            // 控制类Buff
            case BuffType.Stun:
                return new StunBuff(buffData, caster, target);
            case BuffType.Freeze:
                return new FreezeBuff(buffData, caster, target);
            case BuffType.Petrify:
                return new PetrifyBuff(buffData, caster, target);
            case BuffType.Snare:
                return new SnareBuff(buffData, caster, target);
            case BuffType.Silence:
                return new SilenceBuff(buffData, caster, target);
            case BuffType.Disarm:
                return new DisarmBuff(buffData, caster, target);
            case BuffType.Blind:
                return new BlindBuff(buffData, caster, target);
            case BuffType.Slow:
                return new SlowBuff(buffData, caster, target);
            case BuffType.Taunt:
                return new TauntBuff(buffData, caster, target);
            case BuffType.Charm:
                return new CharmBuff(buffData, caster, target);
            case BuffType.Fear:
                return new FearBuff(buffData, caster, target);
            case BuffType.Confuse:
                return new ConfuseBuff(buffData, caster, target);
            case BuffType.Sleep:
                return new SleepBuff(buffData, caster, target);

            // 防御类Buff
            case BuffType.Invincible:
                return new InvincibleBuff(buffData, caster, target);
            case BuffType.SuperArmor:
                return new SuperArmorBuff(buffData, caster, target);
            case BuffType.SpellShield:
                return new SpellShieldBuff(buffData, caster, target);
            case BuffType.PhysicalShield:
                return new PhysicalShieldBuff(buffData, caster, target);
            case BuffType.MagicImmune:
                return new MagicImmuneBuff(buffData, caster, target);
            case BuffType.Cleanse:
                return new CleanseBuff(buffData, caster, target);
            case BuffType.Revive:
                return new ReviveBuff(buffData, caster, target);

            // 移动类Buff
            case BuffType.Knockback:
                return new KnockbackBuff(buffData, caster, target);
            case BuffType.Pull:
                return new PullBuff(buffData, caster, target);
            case BuffType.KnockUp:
                return new KnockUpBuff(buffData, caster, target);
            case BuffType.BlowAway:
                return new BlowAwayBuff(buffData, caster, target);
            case BuffType.Grapple:
                return new GrappleBuff(buffData, caster, target);
            case BuffType.Swap:
                return new SwapBuff(buffData, caster, target);
            case BuffType.Blink:
                return new BlinkBuff(buffData, caster, target);
            case BuffType.Dash:
                return new DashBuff(buffData, caster, target);

            // 属性类Buff
            case BuffType.AttrData:
                return new AttrBuff(buffData, caster, target);
            case BuffType.Thorns:
                return new ThornsBuff(buffData, caster, target);
            case BuffType.Weakness:
                return new WeaknessBuff(buffData, caster, target);
            case BuffType.ArmorShred:
                return new ArmorShredBuff(buffData, caster, target);
            case BuffType.Vulnerability:
                return new VulnerabilityBuff(buffData, caster, target);
            case BuffType.Sluggish:
                return new SluggishBuff(buffData, caster, target);

            // 其他Buff
            case BuffType.Stealth:
                return new StealthBuff(buffData, caster, target);
            case BuffType.Summon:
                return new SummonBuff(buffData, caster, target);

            default:
                Logger.LogWarning("BuffFactory", $"未找到Buff类型 {buffType} 的实现");
                return null;
        }
    }

    /// <summary>
    /// 根据BuffData直接创建Buff
    /// </summary>
    /// <param name="buffData">Buff数据</param>
    /// <param name="caster">施法者</param>
    /// <param name="target">目标</param>
    /// <returns>创建的Buff实例</returns>
    public static BuffBase CreateBuff(BuffData buffData, Entity caster, Entity target)
    {
        Logger.Log("BuffFactory", $"CreateBuff 被调用，buffName={buffData?.BuffName}, buffType={buffData?.BuffType}, caster={caster?.name}, target={target?.name}");
        
        if (buffData == null)
        {
            Logger.LogError("BuffFactory", "BuffData 为空！");
            return null;
        }
        
        if (target == null)
        {
            Logger.LogError("BuffFactory", $"Target 为空！buffName={buffData.BuffName}");
            return null;
        }
        
        var result = CreateBuff(buffData.BuffType, buffData, caster, target);
        
        if (result != null)
        {
            Logger.Log("BuffFactory", $"Buff创建成功: {buffData.BuffName} (类型={buffData.BuffType}), target={target.name}");
        }
        else
        {
            Logger.LogError("BuffFactory", $"Buff创建失败: {buffData.BuffName} (类型={buffData.BuffType}), target={target.name}");
        }
        
        return result;
    }
}